using System;

namespace HEFramework
{
    /// <summary>
    ///
    /// StreamingAssets模式
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-12-21 14:26:54
    /// ----------------------------------------
    /// </summary>
    public class Streaming_AssetLoad : IAssetLoad
    {
        public T LoadAssetSyn<T>(string _assetBundleName, string _assetName, string _extension) where T : UnityEngine.Object
        {
            string assetBundleName = _assetBundleName.ToLower();
            if (AssetBundleSettingScriptableObject.Instance.Encrypt)
            {
                assetBundleName = MD5Hash.ComputeHashToHex(assetBundleName);
            }

            string assetBundleFilePath = AssetBundleSettingScriptableObject.Instance.GetAssetBundleDataLoadPath() + "/" + assetBundleName;
            return AssetBundleLoader.Instance.LoadAssetSyn<T>(assetBundleFilePath, assetBundleName, _assetName);
        }

        public void LoadAssetAsync<T>(string _assetBundleName, string _assetName, string _extension, Action<T> _callback) where T : UnityEngine.Object
        {
            string assetBundleName = _assetBundleName.ToLower();
            if (AssetBundleSettingScriptableObject.Instance.Encrypt)
            {
                assetBundleName = MD5Hash.ComputeHashToHex(assetBundleName);
            }

            string assetBundleFilePath = AssetBundleSettingScriptableObject.Instance.GetAssetBundleDataLoadPath() + "/" + assetBundleName;
            AssetBundleLoader.Instance.LoadAssetAsync<T>(assetBundleFilePath, assetBundleName, _assetName, _callback);
        }

        public void UnLoadAssetAsync(string _assetBundleName)
        {
            string assetBundleName = _assetBundleName.ToLower();
            if (AssetBundleSettingScriptableObject.Instance.Encrypt)
            {
                assetBundleName = MD5Hash.ComputeHashToHex(assetBundleName);
            }

            AssetBundleLoader.Instance.UnLoadAssetAsync(assetBundleName);
        }
    }
}